<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/6/006
 * Time: 10:35
 */

namespace app\api\model;


use app\api\service\Token;
use app\api\model\Address as AddressModel;
use app\api\model\Product as ProductModel;
use app\api\model\ProductAttr as ProductAttrModel;
use app\api\model\AttrValue as AttrValueModel;
use app\lib\exception\OrderException;
use app\lib\exception\ProductAttrException;
use app\lib\exception\ProductException;
use app\lib\exception\AddressException;
use app\api\model\Member as MemberModel;
use app\api\service\Order as OrderService;
use app\api\model\OrderBuyProduct as OrderBuyProductModel;
use think\Db;
use think\Exception;

class OrderRecharge extends BaseModel {

    protected $hidden = ['update_time','create_time'];
    /**
     * 订单用户
     * @return \think\model\relation\belongsTo
     */
    public function orderMember() {
        return $this->belongsTo('Member');
    }

    /**
     * 创建充值订单
     * @param $param
     * @return static
     */
    public static function createRecharge($param) {
        $uid = Token::getCurrentUid();
        $order_data = [
            'order_sn' => 'CZ' . date('YmdHis') . rand(1000, 9999),
            'member_id' => $uid,
            'money' => $param['money'],
            'source' => $param['source']
        ];
        return self::create($order_data);
    }
}